import java.awt.*;
import java.awt.event.*;
/**
 * Die Welt in der Automaten über N "leben"
 *
 * @author henry@freye.de
 *
 */
public class WeltN2 extends Frame implements WindowListener{
        /*
         * Die Zeichenmethode
         */
        public void paint(Graphics g){
                System.out.println("Position"+aktorPosition.getX()+","+aktorPosition.getY());
                int breite = this.getWidth();
                int hoehe = this.getHeight()+20;
                //System.out.println("paint "+breite+","+hoehe);
                //Hintergrund einfärben
                g.setColor(new Color(230,230,230));
                g.fillRect(0, 0, breite, hoehe);
                g.setColor(new Color(0,0,200));
                //Achsen zeichen
                g.drawLine(20,hoehe-50, breite-20,hoehe-50);
                g.drawLine(20,hoehe-50, 20, 70);

                for (int i=0; i<= max;i++){
                        int b = i*(breite-40)/(max)+20;
                        g.drawLine(b,hoehe-45,b,hoehe-55);
                        g.drawLine(15,hoehe-30-b,25,hoehe-30-b);
                }
                g.drawString("0", 12, hoehe-35);

                g.setColor(Color.RED);

                g.drawOval(aktorPosition.getX()*(breite-40)/(max)+20-8, hoehe-(aktorPosition.getY()*(hoehe-160)/(max)+50)-8, 16, 16);
        }

        /**
         * Damit man die Klasse theoretisch speichern kann
         */
        private static final long serialVersionUID = -1734249687065243767L;
        private int max;
        private Punkt aktorPosition;

        /**
         * @param String title
         */
        public WeltN2(String title){
                super(title);
                this.setSize(500, 600);
                this.setVisible(true);
                this.addWindowListener(this);
                this.max = 10;
                aktorPosition = new Punkt();
        }
        public void setAktor(Punkt pos){
                aktorPosition = pos;
        }

        public void gehe(Punkt p){
                aktorPosition.add(p);
                this.repaint();
        }

        public Punkt getPosistion(){
                int tx = 0;
                int ty = 0;
                if (aktorPosition.getX() > 0){
                        tx = 1;
                }
                if (aktorPosition.getY() > 0){
                        ty = 1;
                }
                return new Punkt(tx,ty);
        }

        /**
         * @param String title
         */
        public WeltN2(String title, int max){
                this(title);
                this.max = max;
                //System.out.println("Neu: max="+max);
        }

        public void windowActivated(WindowEvent arg0) { }
        public void windowClosed(WindowEvent arg0) {}
        public void windowClosing(WindowEvent arg0) {
                System.exit(0);
                this.dispose();
        }
        public void windowDeactivated(WindowEvent arg0) {       }
        public void windowDeiconified(WindowEvent arg0) {       }
        public void windowIconified(WindowEvent arg0) {}
        public void windowOpened(WindowEvent arg0) {}
}
